<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>
    <template>
      <el-row :gutter="60">
        <el-col :span="6">
          <el-input placeholder="请输入搜索内容"
                    suffix-icon="el-icon-search"
                    v-model="queryParam.query"
                    @change="getUserList"
                    @clear="getUserList">
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="success"
                     @click="addUser">添加用户</el-button>
          <el-dialog title="填写信息"
                     :visible.sync="dialogFormVisible">
            <el-form :model="form">
              <el-form-item label="姓名"
                            :label-width="formLabelWidth"></el-form-item>
              <el-input v-model="form.name"
                        autocomplete="off"
                        :width="width"></el-input>
              <el-form-item label="职位"
                            :label-width="formLabelWidth"></el-form-item>
              <el-input v-model="form.status"
                        autocomplete="off"
                        :width="width"></el-input>
              <el-form-item label="邮箱"
                            :label-width="formLabelWidth"></el-form-item>
              <el-input v-model="form.email"
                        autocomplete="off"
                        :width="width"></el-input>
            </el-form>
            <div slot="footer"
                 class="dialog-footer">
              <el-button @click="dialogFormVisible = false">取 消</el-button>
              <el-button type="primary"
                         @click="dialogFormVisible = false">确 定</el-button>

            </div>
          </el-dialog>
        </el-col>
      </el-row>

      <el-table :data="userList"
                border
                style="width: 100%">
        <el-table-column type="index"
                         label="序号"
                         width="50">
        </el-table-column>
        <el-table-column prop="username"
                         label="姓名"
                         width="150">
        </el-table-column>
        <el-table-column prop="role_name"
                         label="职位"
                         width="150">
        </el-table-column>
        <el-table-column prop="mobile"
                         label="电话"
                         width="150">
        </el-table-column>
        <el-table-column prop="email"
                         label="邮箱"
                         width="150">
        </el-table-column>
        <el-table-column prop="mg_state"
                         label="状态"
                         width="150">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.mg_state"
                       active-color="#13ce66"
                       inactive-color="#ff4949">
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作"
                         width="250">
          <template slot-scope="scope">
            <el-row>
              <el-button icon="el-icon-edit"
                         circle
                         @click="scope.row.id"></el-button>
              <el-button type="primary"
                         icon="el-icon-setting"
                         circle></el-button>
              <el-button type="danger"
                         icon="el-icon-delete"
                         circle></el-button>
            </el-row>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination @size-change="handleSizeChange"
                     @current-change="handleCurrentChange"
                     :current-page="queryParam.pagenum"
                     :page-sizes="[4,1,2,3]"
                     :page-size="queryParam.pagesize"
                     layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>
    </template>

  </div>
</template>

<script>
export default {
  name: 'users',
  data () {
    return {
      userList: [],
      input: '',
      queryParam: {
        query: '',
        pagenum: 1,
        pagesize: 10
      },
      total: 0,
      dialogTableVisible: false,
      dialogFormVisible: false,
      formLabelWidth: '120px',
      form: {
        name: '',
        status: '',
        email: ''
      },
      width: '50px'
    }
  },
  created () {
    this.getUserList()
  },
  methods: {
    async getUserList () {
      const { data: res } = await this.$myAxios.get('users', { params: this.queryParam })
      console.log(res)
      this.userList = res.data.users
      this.total = res.data.total
    },
    handleSizeChange (pagesize) {
      this.queryParam.pagesize = pagesize
      this.getUserList()
    },
    handleCurrentChange (pagenum) {
      this.queryParam.pagenum = pagenum
      this.getUserList()
    },
    addUser () {
      this.dialogFormVisible = 'true'
    }
  }

}
</script>

<style lang="less" scope>
.el-breadcrumb {
  margin-top: 5px;
  margin-bottom: 10px;
}
.el-input .el-col .el-table {
  margin-top: 5px;
  margin-bottom: 5px;
}
</style>
